package au.com.betaversion.controller;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import au.com.betaversion.tmdb.TMDbClient;

/**
 * Handles requests for the application home page.
 */
@Controller
public class HomeController {
	
	private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
	
	@Autowired
	private TMDbClient tmDbClient;
	
	/**
	 * Simply selects the home view to render by returning its name.
	 */
	@RequestMapping(value = "/home", method = RequestMethod.GET)
	public String home(Model model) {
		return "home";
	}
	
	@RequestMapping(value = "/home/{movieId}", method = RequestMethod.GET, headers = {"Accept=application/json"})
	public @ResponseBody Map<?, ?> home(@PathVariable String movieId) {
		logger.info("Movie Id to be retrieved: " + movieId);
		Map<?, ?> result = tmDbClient.getMovie(movieId);
		return result;
	}
	
}